# python3

# 15th of april, 2010
#


import unittest

daynames_eng = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]
normal_worker = [1,1,1,1,1,0,0] # saturday and sunday are no-work days

def weeklist_truth_names(truthtable, names):
	'''Return incrementally the name of the day in name if it match 1 in the truth table.'''
	if len(truthtable) != len(names):
		raise ValueError("Truth table and week must have same length")
	if truthtable.count(0) == len(truthtable):
		raise ValueError("You must work at least one day a week!")
	i = 0
	l = len(names)
	while 1:
		if truthtable[i%l]:
			yield names[i%l]
		i += 1

def weeklist_eng(truthtable):
	'''Return incrementally the english name of the day if it match 1 in the truth table.'''
	return weeklist_truth_names(truthtable, daynames_eng)

def weeklist():
	'''Return incrementally the english name of the day if it is a normal work day.'''
	return weeklist_eng(normal_worker)


class Test_week(unittest.TestCase):
	def test_bad(self):
		itr = weeklist_truth_names(["Monday"], [0,1])
		self.assertRaises(ValueError, next, itr)
		itr = weeklist_eng([0,0,0,0,0,0,0])
		self.assertRaises(ValueError, next, itr)

	def test_go(self):
		itr = weeklist()
		i0 = next(itr)
		s = i0 
		for i in itr:
			if i==i0: break
			s += i
		s1 = "".join(daynames_eng[i] for i in range(len(daynames_eng)-2))
		#print(s, i0, s1)
		self.assertEqual(s,s1)

if __name__ == "__main__":
	unittest.main()
